from django.db.transaction import commit_on_success
from duetopia.register.models import DataSet
from transform import parse, transform
import RDF

__all__ = ["save"]

@commit_on_success
def save(uri):
	model = parse(uri)
	rdf_type = RDF.Uri("http://www.w3.org/1999/02/22-rdf-syntax-ns#type")
	sweet_dataset = RDF.Uri("http://sweet.jpl.nasa.gov/1.1/data.owl#Dataset")
	s = RDF.Statement(None, rdf_type, sweet_dataset)
	for r in model.find_statements(s):
		DataSet.objects.rdf_get_or_create(model, r.subject)

if __name__ == "__main__":
	from sys import argv
	save(argv[1])
